home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Ebooks / Thinking in C++ V2 / C02 / Fillvector.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-25  |  593 b   |  23 lines

  1. //: C02:Fillvector.cpp
  2. // From Thinking in C++, 2nd Edition
  3. // Available at http://www.BruceEckel.com
  4. // (c) Bruce Eckel 1999
  5. // Copyright notice in Copyright.txt
  6. // Copy an entire file into a vector of string
  7. #include <string>
  8. #include <iostream>
  9. #include <fstream>
  10. #include <vector>
  11. using namespace std;
  12.  
  13. int main() {
  14.   vector<string> v;
  15.   ifstream in("Fillvector.cpp");
  16.   string line;
  17.   while(getline(in, line))
  18.     v.push_back(line); // Add the line to the end
  19.   // Add line numbers:
  20.   for(int i = 0; i < v.size(); i++)
  21.     cout << i << ": " << v[i] << endl;
  22. } ///:~
  23.